package com.chookss.home.audit.reimbursement;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.MyApp;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.FileEntity;
import com.chookss.tools.MyEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;

import io.reactivex.annotations.Nullable;

public class ReimbursementTypeAdapter extends BaseQuickAdapter<FileEntity, BaseViewHolderEx> {
    private Activity context;

    public ReimbursementTypeAdapter(int layoutResId, Activity context, @Nullable List<FileEntity> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, FileEntity entity) {

        TextView tvItemTitle = helper.getView(R.id.tvItemTitle);
        LinearLayout llAll = helper.getView(R.id.llAll);
        tvItemTitle.setText(entity.getBaoixaoTypeName());
        if (entity.isSelect()) {
            llAll.setBackgroundColor(Color.parseColor("#FFF8EF"));
        } else {
            llAll.setBackgroundColor(Color.parseColor("#FFFFFF"));
        }
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (entity.isSelect()) {
                    MyApp.fileEntity=null;
                    entity.setSelect(false);
                } else {
                    if (MyApp.fileEntity!=null) {
                        HashMap<String, String> map = new HashMap<>();
                        map.put("clear_baoixaoTypeCode", MyApp.fileEntity.getBaoixaoTypeCode());
                        EventBus.getDefault().post(new MyEvent(map));
                    }
                    MyApp.fileEntity=entity;
                    entity.setSelect(true);
                }
                notifyItemChanged(helper.getItemPosition());
            }
        });
    }
}
